package wsem.model;

import java.util.ArrayList;
import java.util.Map;

import wsem.utils.SparqlClient;

public class SparqlQuery {


/**
* 
*/
private SparqlClient client;

/**
* 
*/
public SparqlQuery() {
    client = new SparqlClient("localhost:8080/space");
}

/**
* 
* @param mot
* @return
*/
public ArrayList<String> getSynonyme(String mot) {
    String query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
                    + "SELECT ?labely WHERE {\n" + "?x rdfs:label ?labelx;\n"
                    + "rdfs:label ?labely.\n"
                    + "FILTER (?labelx != ?labely && regex(?labelx, \"" + mot
                    + "\"))\n" + "}";

    Iterable<Map<String, String>> results = client.select(query);
    ArrayList<String> liste = new ArrayList<String>();
    for (Map<String, String> result : results) {
            liste.add(result.get("labely"));
            System.out.println(result.get("labely"));
    }
    return liste;
}

/**
* 
* @param individu
* @return
*/
public ArrayList<String> getFils(String individu) {
	ArrayList<String> liste = new ArrayList<String>();
	String[] tabmot = individu.split(" ");
	for (String mot : tabmot)
	{
		String query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
                    + "PREFIX :<http://www.semanticweb.org/clement/ontologies/2014/0/Ontologie-Balades#>\n"
                    + "SELECT ?child WHERE {\n" + "?child rdfs:subClassOf :"
                    + mot + ".\n" + "}";

    Iterable<Map<String, String>> results = client.select(query);   
    for (Map<String, String> result : results) {
            liste.add(result.get("child"));
            System.out.println(result.get("child"));
    	}
	}
    return liste;
}
}
